import Operations from "./Operations";
import { InsertTextOperation } from "./index";
export class RemoveTextOperation extends Operations {
  startIndex_;
  endIndex_;
  spacers_;
  constructor(startIndex, endIndex) {
    super();
    this.startIndex_ = startIndex;
    this.endIndex_ = endIndex;
    this.type = "RemoveOpt";
  }
  apply(editor) {
    let { startIndex_, endIndex_ } = this;
    // 保证插入时始终是在开始位置插入(存在选区时开始位置可能大于结束位置)
    if (startIndex_ > endIndex_) {
      [startIndex_, endIndex_] = [endIndex_, startIndex_];
    }
    this.spacers_ = editor
      .getTextModel()
      .getSpacersByIndex(startIndex_, endIndex_);
    editor.getTextModel().remove(this.startIndex_, this.endIndex_);
  }
  reverse() {
    let { startIndex_, endIndex_ } = this;

    // 保证插入时始终是在开始位置插入(存在选区时开始位置可能大于结束位置)
    if (startIndex_ > endIndex_) {
      [startIndex_, endIndex_] = [endIndex_, startIndex_];
    }
    console.log(startIndex_, endIndex_);
    return new InsertTextOperation(this.spacers_, startIndex_);
  }
}
export default RemoveTextOperation;
